<html>
<head><meta charset="utf-8"><title>Generic over smart pointers · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Generic.20over.20smart.20pointers.html">Generic over smart pointers</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231684434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Generic%20over%20smart%20pointers/near/231684434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nick Hu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Generic.20over.20smart.20pointers.html#231684434">(Mar 24 2021 at 18:23)</a>:</h4>
<p>Hi, I'm trying to write some code that is reasonably generic over smart pointers. One thing I'm struggling with is that say I have an instance of</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="nb">From</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"></span>
</code></pre></div>
<p>Then I want to freely convert from <code>Box</code>ed/un-<code>Box</code>ed <code>U</code> to <code>Box</code>ed/un-<code>Box</code>ed <code>T</code> with a mere <code>.into()</code> (is this considered idiomatic or not, by the way?); do I have any better options than writing</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="nb">From</span><span class="o">&lt;</span><span class="nb">Box</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="nb">From</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">Box</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="nb">From</span><span class="o">&lt;</span><span class="nb">Box</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">Box</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"></span>
</code></pre></div>
<p>for all my types? It seems that some combination of orphan rules/conflicting blanket implementations prevents me from doing this generically too.</p>
<p>It's even worse when I think about how I might want some for reference types too</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>